<template>
  <div class="info-container">
    <el-card style="height: 100%">
      <search-tool @onSearch="handleSearch"></search-tool>
      <div class="addmore">
        <!-- <el-button type="primary" @click="addMore">添加</el-button> -->
      </div>
      <el-table
        :data="tableData"
        style="width: 100%"
        v-loading="loading"
        height="75%"
        align-items="center"
      >
        <el-table-column label="序号" type="index" />
        <el-table-column prop="pipeName" label="所属管廊" width="180" />
        <el-table-column prop="storehouseName" label="所属仓室" width="180" />
        <el-table-column prop="subregionName" label="防火分区" width="180" />
        <el-table-column prop="address" label="地理位置" width="180" />
        <el-table-column prop="problemDesc" label="问题描述" width="180" />
        <el-table-column prop="userName" label="上报人" width="180" />
        <el-table-column prop="reportTime" label="上报时间" width="180" />
        <el-table-column label="问题图片(数量)" width="150">
          <template #default="{ row }">
            <!-- <span>{{ row.fileInfoList[0] || '1' }}</span> -->
            <span class="title-img">
              <el-image
                class="pic"
                style="width: 38px; height: 38px"
                :src="row.fileInfoList[0]?.fileUrl"
                :preview-src-list="row.arr"
                fit="cover"
              />
              <!-- :preview-src-list="row.fileInfoList" -->
              <!-- :src="row.fileInfoList[0]?.fileUrl || []" -->

              <span
                class="table-title"
                style="margin-right: 10px; margin-left: 10px"
                >{{ row.fileInfoList?.length }}</span
              >
            </span>
            <!-- <div>
              <svg-icon
                class="pic"
                style="cursor: pointer"
                icon="photo"
                @click="tp(row)"
              ></svg-icon>
              <span style="margin-right: 10px; margin-left: 10px">1</span>
            </div> -->
          </template>
        </el-table-column>
        <el-table-column prop="dealStatus" label="当前状态" width="180" />
        <el-table-column label="操作" width="120">
          <template #default="{ row }">
            <div class="action-row">
              <div>
                <div
                  v-show="
                    row.dealStatus === '未确认' || row.dealStatus === '处置中'
                  "
                >
                  <el-tooltip content="分析处置" placement="top" effect="light">
                    <svg-icon
                      class="iconsty"
                      icon="run-product-disposal"
                      @click="editRow(row)"
                    ></svg-icon>
                  </el-tooltip>
                </div>
                <div
                  v-show="
                    row.dealStatus !== '未确认' && row.dealStatus !== '处置中'
                  "
                >
                  <svg-icon class="iconsty" icon="product-forb"></svg-icon>
                </div>
              </div>
              <div>
                <div
                  v-show="
                    row.dealStatus === '已处置' || row.dealStatus === '误报'
                  "
                >
                  <el-tooltip content="警报解除" placement="top" effect="light">
                    <svg-icon
                      class="iconsty"
                      icon="run-product-relieve"
                      style="margin-right: 10px; margin-left: 10px"
                      @click="relieve(row)"
                    ></svg-icon>
                  </el-tooltip>
                </div>
                <div
                  v-show="
                    row.dealStatus !== '已处置' && row.dealStatus !== '误报'
                  "
                >
                  <svg-icon
                    class="iconsty"
                    icon="product-forbjc"
                    style="margin-right: 10px; margin-left: 10px"
                  ></svg-icon>
                </div>
              </div>

              <div>
                <el-tooltip content="流程查看" placement="top" effect="light">
                  <svg-icon
                    class="iconsty"
                    icon="run-product-view"
                    @click="flow(row)"
                  ></svg-icon>
                </el-tooltip>
              </div>
              <div class="has-more"></div>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        class="pagination"
        :currentPage="page"
        :page-sizes="[5, 10, 20]"
        :page-size="size"
        layout="prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <add-dialog
      :title="dialogTitle"
      :rowData="curRowData"
      v-model:visible="visibleDialog"
      @onReload="reloadPage"
    ></add-dialog>
    <relieve-dialog
      :title="dialogTitle"
      :rowData="curRowData"
      v-model:visible="RelVisibleDialog"
      @onReload="reloadPage"
    >
    </relieve-dialog>
    <flow-dialog
      :title="dialogTitle"
      :rowData="curRowData"
      v-model:visible="flowVisibleDialog"
      @onReload="reloadPage"
    ></flow-dialog>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import SearchTool from './components/SearchTool/index.vue'
import AddDialog from './components/AddDialog/index.vue'
import relieveDialog from './components/AddDialog/relieve.vue'
import flowDialog from './components/AddDialog/flow.vue'
import { problemList, ListDelet } from '@/api/maintain'
import { ElMessageBox } from 'element-plus'
import { message } from '@/utils/message'
import { identifier } from '@babel/types'

const params = ref({})
const tableData = ref([])
const loading = ref(false)
const page = ref(1)
const total = ref(0)
const size = ref(8)
const problemNo = ref('')
const id = ref('')
const dialogTitle = ref('新建工单')
const visibleDialog = ref(false)
const RelVisibleDialog = ref(false)
const flowVisibleDialog = ref(false)
const List = ref([])
const curRowData = ref({})

// 查询所有数据
const getListData = async (params) => {
  loading.value = true
  const res = await problemList(params, page.value, size.value)
  loading.value = false
  tableData.value = res.rows
  List.value = res.rows
  // console.log(res.rows[2])
  // console.log(res.rows[2].fileInfoList[0])
  List.value.forEach((item) => {
    item.arr = []
    // ph.value.push(item.photos)
    // console.log(fileInfoList.value)
    item.fileInfoList.forEach((val) => {
      item.arr.push(val.fileUrl)
      // console.log(val)
    })
  })
  console.log(List.value)
  total.value = res.total
}
getListData(params.value)

//查询条件相关
const handleSearch = (paramsData) => {
  params.value = paramsData
  getListData(paramsData)
}
const reloadPage = () => {
  getListData(params.value)
  visibleDialog.value = false
  flowVisibleDialog.value = false
  RelVisibleDialog.value = false
}
// 编辑信息
const editRow = (row) => {
  dialogTitle.value = '分析处置'
  curRowData.value = row
  visibleDialog.value = true
}
const relieve = (row) => {
  console.log('2323')
  dialogTitle.value = '解除维护'
  curRowData.value = row
  RelVisibleDialog.value = true
}
const flow = (row) => {
  dialogTitle.value = '流程处理'
  curRowData.value = row
  flowVisibleDialog.value = true
  problemNo.value = row.problemNo
  id.value = row.id
}

const handleSizeChange = (val) => {
  size.value = val
  getListData(params.value)
}
const handleCurrentChange = (val) => {
  page.value = val
  getListData(params.value)
}
</script>

<style lang="scss" scoped>
.info-container {
  width: 100%;
  height: 100%;
  .pic {
    text-align: center;
    vertical-align: middle;
  }
  .add-btn {
    width: 80px;
    height: 36px;
    font-size: 16px;
    font-family: Microsoft YaHei;
    // color: #ff9502;
    box-sizing: border-box;
    cursor: pointer;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.39);
    border: 1px solid #ff9502;
    box-shadow: 0px 0px 4px rgba(206, 206, 206, 0.3);
    text-align: center;
    line-height: 36px;
    &:hover {
      background: #ff950236;
    }
  }
  .pagination {
    width: 100%;
    height: 32px;
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: end;
  }
  .action-row {
    display: flex;
    justify-content: space-around;
    .iconsty {
      cursor: pointer;
    }
    :deep(.svg-icon) {
      outline: 0;
    }
    .action-btn {
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      line-height: 19px;
      color: #547bf1;
      cursor: pointer;
    }
    .has-more {
      width: 2px;
      height: 10px;
      margin-right: 10px;
      margin-left: 10px;
      margin-top: 5px;
    }
  }
}
:deep .el-table th,
:deep .el-table td {
  text-align: center !important;
}
</style>
